﻿<UserControl x:Class="VmroleAuthor.Views.ResourceExtensionReferenceView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:vm="clr-namespace:VmroleAuthor.ViewModels"
             mc:Ignorable="d" 
            d:DesignWidth="900">
    <UserControl.Resources>
        <Style x:Key="TextBlockStyle" TargetType="{x:Type TextBlock}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid VerticalAlignment="Top" ShowGridLines="False">
        <Grid.RowDefinitions >
            <RowDefinition Height="6" />
            <RowDefinition Height="Auto" />
            <RowDefinition MinHeight="30" />
            <RowDefinition Height="Auto" />
            <RowDefinition MinHeight="30" />
            <RowDefinition Height="Auto" />
            <RowDefinition MinHeight="30" />
            <RowDefinition Height="Auto" />
            <RowDefinition MinHeight="30" />
            <RowDefinition Height="Auto" />
            <RowDefinition MinHeight="30" />
            <RowDefinition Height="Auto" />
            <RowDefinition MinHeight="30" />
            <RowDefinition Height="Auto" />           
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="6"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="6"/>
        </Grid.ColumnDefinitions>

        <!-- Auto Populate -->
        <Label Grid.Row="1" Grid.Column="0" >Select to Auto Populate</Label>
        <ListBox x:Name="AutoPopulate" Grid.Row="1" Grid.Column="2"  
                 BorderThickness="0"
                 ItemsSource="{Binding Path=AvailableResourceExtensionReferencesForAutoPopulate}" 
                 SelectedItem="{Binding Path=SelectedAutoPopulateResourceExtensionReference, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}">          
            <ListBox.ItemTemplate>
                <DataTemplate DataType="vm:VmRoleResourceExtensionViewModel">
                    <RadioButton  IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}},Path=IsSelected}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="6"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="6"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>                          
                            <TextBlock  Grid.Column="0" Text="{Binding Name}"/>
                            <TextBlock  Grid.Column="2" Text="{Binding Publisher}"/>
                            <TextBlock  Grid.Column="4" Text="{Binding Version}"/>
                        </Grid>
                    </RadioButton>                   
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <ContentPresenter Grid.Row="2" Grid.Column="2" Content="{Binding ElementName=AutoPopulate, Path=(Validation.Errors).CurrentItem}" />

        <!--Reference Name-->
        <Label Grid.Row="3" Grid.Column="0" >Reference Name</Label>
        <TextBox x:Name="ReferenceName" Grid.Row="3" Grid.Column="2" Text="{Binding ReferenceName, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" />
        <ContentPresenter Grid.Row="4" Grid.Column="2" Content="{Binding ElementName=ReferenceName, Path=(Validation.Errors).CurrentItem}" />

        <!--Name-->
        <Label Grid.Row="5" Grid.Column="0" >Name</Label>
        <TextBox x:Name="ExtName" Grid.Row="5" Grid.Column="2" Text="{Binding Name, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" />
        <ContentPresenter Grid.Row="6" Grid.Column="2" Content="{Binding ElementName=ExtName, Path=(Validation.Errors).CurrentItem}" />

        <!--Publisher-->
        <Label Grid.Row="7" Grid.Column="0" >Publisher</Label>
        <TextBox x:Name="Publisher" Grid.Row="7" Grid.Column="2" Text="{Binding Publisher, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" />
        <ContentPresenter Grid.Row="8" Grid.Column="2" Content="{Binding ElementName=Publisher, Path=(Validation.Errors).CurrentItem}" />

        <!--Version-->
        <Label Grid.Row="9" Grid.Column="0" >Version</Label>
        <TextBox x:Name="Version" Grid.Row="9" Grid.Column="2" Text="{Binding Version, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" />
        <ContentPresenter Grid.Row="10" Grid.Column="2" Content="{Binding ElementName=Version, Path=(Validation.Errors).CurrentItem}" />

        <!-- Resource Extension Parameters -->
        <Label  Grid.Row="11" Grid.Column="0" >Resource Extension Parameters</Label>
        <DataGrid  x:Name="ResourceExtensionParameterHolders" Grid.Row="11" Grid.Column="2" AutoGenerateColumns="False" IsReadOnly="False" CanUserAddRows="False" CanUserDeleteRows="False" ItemsSource="{Binding ResourceExtensionParameterHolderViewModels, ValidatesOnExceptions=True}">
            <DataGrid.RowStyle>
                <Style TargetType="DataGridRow">
                    <Setter Property="ValidationErrorTemplate" Value="{x:Null}"/>
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="BorderBrush" Value="Blue" />
                            <Setter Property="BorderThickness" Value="2" />
                            <Setter Property="Background" Value="LightBlue" />
                            <Setter Property="Foreground" Value="Black" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.RowStyle>
            <DataGrid.CellStyle>
                <Style TargetType="DataGridCell">
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Background" Value="White" />
                            <Setter Property="Foreground" Value="Black" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.CellStyle>
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="Parameter Name" MinWidth="250">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Style="{StaticResource ResourceKey=TextBlockStyle}" Text="{Binding ParameterName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding ParameterName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, Mode=TwoWay,  NotifyOnValidationError=True}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Param In Resdef?">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox Style="{StaticResource ResourceKey=CheckBoxStyle}"   IsChecked="{Binding ParameterValue.IsParameterized,  UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True,  NotifyOnValidationError=True}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <CheckBox Style="{StaticResource ResourceKey=CheckBoxStyle}" IsChecked="{Binding ParameterValue.IsParameterized, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True, Mode=TwoWay, NotifyOnValidationError=True}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Parameter Value" MinWidth="350">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Style="{StaticResource ResourceKey=TextBlockStyle}" Text="{Binding ParameterValue.PropertyValue,  ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <ComboBox x:Name="ParamValue" IsEditable="True" 
                                      ItemsSource="{Binding  AvailableParameters}" 
                                      SelectedItem="{Binding ParameterValue.SelectedPropertyValue}" 
                                      Text="{Binding ParameterValue.PropertyValue, UpdateSourceTrigger=LostFocus, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"
                                      />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
        <ContentPresenter Grid.Row="12" Grid.Column="2" Content="{Binding ElementName=ResourceExtensionParameterHolders, Path=(Validation.Errors).CurrentItem}" />


        <!-- Insert or Delete Rows using button -->
        <StackPanel Orientation = "Horizontal" HorizontalAlignment="Left" Grid.Row="13" Grid.Column="2" >
            <Grid>
                <Grid.RowDefinitions >
                    <RowDefinition Height="6" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="6" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>                   
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="10"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Button Grid.Row="1" Grid.Column="0" Command="{Binding AddResourceExtensionParameterHolderCommand}" >
                    <StackPanel Orientation = "Horizontal">
                        <Image  Source="..\Img\addgreen.png" Width="20" Height="20" ></Image>
                        <TextBlock Margin="5,0,0,0">Insert</TextBlock>
                    </StackPanel>
                </Button>
                <Button Grid.Row="1" Grid.Column="2" Command="{Binding DeleteResourceExtensionParameterHolderCommand}" CommandParameter="{Binding ElementName=ResourceExtensionParameterHolders, Path=SelectedItem}">
                    <StackPanel Orientation = "Horizontal">
                        <Image  Source="..\Img\deletered.png" Width="20" Height="20"></Image>
                        <TextBlock Margin="5,0,0,0">Delete</TextBlock>
                    </StackPanel>
                </Button>              
            </Grid>
        </StackPanel>

    </Grid>
</UserControl>
